"""
filename: createForm.py
create form from a json source
"""

# read the json file

def getJsonData(args):
    if args.fnpath:
        import json
        jsondata = open(args.fnpath)
        data = json.load(jsondata)
        jsondata.close()
        return data

def prettyPrintJson(data):
    from pprint import pprint
    return pprint(data)

def prettyPrintHtml(data):
    # import cheetah template
    from Cheetah.Template import Template
    f = open('conference-form.template.html')
    templateDef = f.read()
    f.close()
    html = Template(templateDef, searchList=[data])

    print html


# get metadata; 
# form type determines whether this is a public form, targeted for specific people, etc. - requires further study
# form class determines whether this is a primary form or secondary form - primary form internally defines everything
# form id is the unique string identifier for all the forms in its system
# form created is the datetime with timezone of form creation
# form owner specifies who the form belongs to - make distinction between owner and assignee, which is a key for the instance data, designating who entered, managed and submitted the data to a data store
# form status - this should also be in the instance data

# section id: designates form namespace to use - we may expand this to a tri level later, or limitless levels, wherein from creators may specify form sections, subsections and subsubsections and so forth...
# question id: unique identifier for a question in the form/section namespace
# question prompt: prompt for the question
# question answer: the answer to the prompt, which really should be in the instance object
# question possible-answers: list specifying possible answers; used in choices, scales
# question class: specifies whether question derives its existence from a pre-specified question class
# question type: specifies whether question will be short-answer, long-answer, choices-multiple-answer, choices-single-answer, or scale

if __name__ == "__main__":
    # get the file from argument
    import argparse
    parser = argparse.ArgumentParser(description='read a json form descripter')
    parser.add_argument('--file','-f', dest='fnpath', help='this is the complete filename and path')
    parser.add_argument('--output-format','-o', dest='outputFormat', help='specify whether format will be json, html - default is json', default='json')
    args = parser.parse_args()

    data = getJsonData(args)
    if not args.outputFormat or args.outputFormat == 'json':
        # call the prettyPrintJson function
        prettyPrintJson(data)
    else:
        prettyPrintHtml(data)

